from loguru import logger
from system.setting import LOG_FILE_LOCATION


class Block:
    def __init__(self, size):
        # 配置日志
        logger.remove()
        f = open(LOG_FILE_LOCATION, "w", encoding="utf-8")
        logger.add(sink=f)
        # 文件块开始的时候存全0
        self.content = []
        # 逻辑size
        self.size = 0
        # 实际size
        self.item_count = 0

    @logger.catch
    def get_content(self):
        return self.content

    def write_content(self, data, size, data_type="object"):
        if data_type == "object":
            self.content = [data]
        elif data_type == "list":
            self.content = data
        self.size = size

    def append_content(self, data, size):
        self.content.append(data)
        self.size += size

    def get_item_count(self):
        return self.item_count

    def get_size(self):
        return self.size

    def init(self):
        self.content = []
